#ifndef LEMC_VALUELIST_H
#define LEMC_VALUELIST_H

#include <vector>
#include <utility>

#include "guielement.h"
#include "scrollbar.h"
#include "../system/global.h"

/*
* A list of selectable options with a scrollbar.
*/
class ValueList : public GuiElement
{
private:
	// The scrollbar.
	ScrollBar* m_scrollbar;

	// Contains all the possible entries.
	std::vector<std::pair<std::string, std::string>> m_entry_list;

	// The number of the entry currently selected.
	int m_active_entry;

	// The height of one entry.
	int m_entry_height;

	// The distance of the scrollbar and the content from the border of the list.
	int m_padding;

	// The width of the scrollbar.
	int m_scrollbar_width;

	// The background graphic.
	std::string m_background_graphic;

	// The graphic of an entry, pressed.
	std::string m_entry_graphic_active;

	// The graphic of an entry, unpressed.
	std::string m_entry_graphic_inactive;

	// The font for the entry labels.
	ALLEGRO_FONT* m_label_font;

	// The color of the entry labels.
	ALLEGRO_COLOR m_label_color;

public:
	/*
	* Creates the list without any entries.
	*
	* @param id The id of the list. This should be unique.
	* @param x The x position of the upper left corner of the list.
	* @param y The y position of the upper left corner of the list.
	* @param size_x Horizontal size of the list.
	* @param size_y Vertical size of the list.
	* @param label_font The font for the entry labels.
	* @param entry_height The height of a single entry.
	* @param padding The distance from the border of the list.
	* @param background_graphic The background of the list.
	* @param entry_graphic_active The graphic of an entry when it's pressed.
	* @param entry_graphic_inactive The graphic of an entry when it's not pressed.
	* @param label_color The color of the labels.
	* @param scrollbar_width The width of the scrollbar.
	* @param scrollbar_button_height The height of the up and down buttons.
	* @param scrollbar_slider_padding The distance of the slider from the scrollbar borders.
	* @param scrollbar_slider_background_graphic The background graphic of the scrollbar.
	* @param scrollbar_slider_height The height of the slider.
	* @param scrollbar_slider_graphic_up The graphic of the slider, unpressed.
	* @param scrollbar_slider_graphic_down The graphic of the slider, pressed.
	* @param scrollbar_button_graphic_top_up The graphic of the top button, unpressed.
	* @param scrollbar_button_graphic_top_down The graphic of the top button, pressed.
	* @param scrollbar_button_graphic_bottom_up The graphic of the bottom button, unpressed.
	* @param scrollbar_button_graphic_bottom_down The graphic of the bottom button, pressed.
	*/
	ValueList(std::string id, int x, int y, int size_x, int size_y, ALLEGRO_FONT* label_font,
		int entry_height = STANDARD_VALUELIST_ENTRY_HEIGHT, int padding = STANDARD_VALUELIST_PADDING,
		std::string background_graphic = STANDARD_VALUELIST_BACKGROUND_GRAPHIC,
		std::string entry_graphic_active = STANDARD_VALUELIST_ENTRY_GRAPHIC_ACTIVE,
		std::string entry_graphic_inactive = STANDARD_VALUELIST_ENTRY_GRAPHIC_INACTIVE,
		const unsigned char label_color[3] = STANDARD_VALUELIST_ENTRY_LABEL_COLOR,
		int scrollbar_width = STANDARD_VALUELIST_SCROLLBAR_WIDTH,
		int scrollbar_button_height = STANDARD_SCROLLBAR_BUTTON_HEIGHT,
		int scrollbar_slider_padding = STANDARD_SCROLLBAR_SLIDER_PADDING,
		std::string scrollbar_slider_background_graphic = STANDARD_SCROLLBAR_SLIDER_BACKGROUND_GRAPHIC,
		int scrollbar_slider_height = STANDARD_SCROLLBAR_SLIDER_HEIGHT,
		std::string scrollbar_slider_graphic_up = STANDARD_SCROLLBAR_SLIDER_GRAPHIC_UP,
		std::string scrollbar_slider_graphic_down = STANDARD_SCROLLBAR_SLIDER_GRAPHIC_DOWN,
		std::string scrollbar_button_graphic_top_up = STANDARD_SCROLLBAR_TOP_BUTTON_GRAPHIC_UP, 
		std::string scrollbar_button_graphic_top_down = STANDARD_SCROLLBAR_TOP_BUTTON_GRAPHIC_DOWN,
		std::string scrollbar_button_graphic_bottom_up = STANDARD_SCROLLBAR_BOTTOM_BUTTON_GRAPHIC_UP,
		std::string scrollbar_button_graphic_bottom_down = STANDARD_SCROLLBAR_BOTTOM_BUTTON_GRAPHIC_DOWN);
	~ValueList();

	/*
	* Adds an entry to the list and adjusts the step value of the scrollbar correctly.
	*
	* @param label The label of the entry.
	* @param value The value of the entry.
	*/
	void AddEntry(std::string label, std::string value);

	/*
	* Gets the value of the currently active element.
	*
	* @param value The string where the value is stored if obtainable.
	*
	* @return True if a value was set and could be obtained, else false.
	*/
	bool GetCurrentValue(std::string& value);

	void PrimaryMouseButtonUp(int x, int y);
	void PrimaryMouseButtonDown(int x, int y);
	void MouseAxisChange(int x, int y);

	void Update();
	void Draw();
};

#endif